clear all
cd "C:\Users\ot3\Documents\TeacherDeseg\Census"


set more off

clear
quietly infix               ///
  int     year       1-4    ///
  byte    datanum    5-6    ///
  double  serial     7-14   ///
  double  hhwt       15-24  ///
  byte    region     25-26  ///
  byte    statefip   27-28  ///
  byte    gq         29-29  ///
  int     pernum     30-33  ///
  double  perwt      34-43  ///
  byte    sex        44-44  ///
  int     age        45-47  ///
  int     birthyr    48-51  ///
  byte    race       52-52  ///
  int     raced      53-55  ///
  byte    hispan     56-56  ///
  int     hispand    57-59  ///
  int     bpl        60-62  ///
  long    bpld       63-67  ///
  byte    educ       68-69  ///
  int     educd      70-72  ///
  byte    empstat    73-73  ///
  byte    empstatd   74-75  ///
  byte    labforce   76-76  ///
  int     occ1950    77-79  ///
  int     ind1950    80-82  ///
  long    incwage    83-88  ///
  byte    migrate5   89-89  ///
  byte    migrate5d  90-91  ///
  int     migplac5   92-94  ///
  using `"usa_00070.dat"'

replace hhwt      = hhwt      / 100
replace perwt     = perwt     / 100

format serial    %8.0g
format hhwt      %10.2f
format perwt     %10.2f



*Note: Data already restricted to non-Hispanic, black or white, at least 1 year college, 

*Race, sex, education, birth place
recode race (1=0)(2=1)(else=.), gen(black)
recode sex (1=1)(2=0), gen(male)
recode educ (7 8 9=1)(10=2) (11=3)  
drop if bpl>56 //missing codes and abroad

*Define regions
g bornsouth=inlist(bpl, 1, 5, 12, 13, 22, 28, 37, 45, 47, 48, 51)
replace bornsouth=. if bpl==.

g livesouth=inlist(statefip, 1, 5, 12, 13, 22, 28, 37, 45, 47, 48, 51)  
replace livesouth=. if statefip==.

*drop if inlist(statefip, 10, 21, 24, 40, 54) 
*drop if inlist(bpl, 10, 21, 24, 40, 54) 


*Employment outcomes
drop if occ1950==997 | occ1950==999

recode empstat (1=0)(2 3=1), gen(notworking)

recode occ1950 (93=1)(else=0), gen(teacher)
replace teacher=0 if notworking==1 //respondents report an occupation if they have wroked in past 10 years, even if not working now

g teacher_newreg=(teacher==1 & livesouth==0 & bornsouth==1) | (teacher==1 & livesouth==1 & bornsouth==0)
g teacher_ownreg=(teacher==1 & livesouth==1 & bornsouth==1) | (teacher==1 & livesouth==0 & bornsouth==0)

recode occ1950 (0/99=1)(else=0), gen(prof)  
replace prof=0 if notworking==1
replace prof=0 if teacher==1

recode occ1950 (0/99=0)(else=1), gen(nonprof)  
replace nonprof=0 if notworking==1
replace nonprof=0 if teacher==1



*earnings
replace incwage=. if incwage>=999998
cpigen
replace incwage=incwage/cpiu
replace incwage=25000/.1717446 if year==1970 & incwage>25000/.1717446
g learn=ln(incwage)

*Means quoted in introduction
tab occ1950 if black==1 & livesouth==1 & year==1960 & notworking==0 [aweight=perwt]

*interaction terms
foreach y of numlist 1940 1950 1960 1970 1980 1990 2000 {
g y`y'=year==`y'
g Sx`y'=bornsouth*y`y'
g Bx`y'=black*y`y'
g BxSx`y'=black*bornsouth*y`y'
}
g BxS=black*bornsouth	
save MainWorking, replace





*Figure 3: Demonstration of approach
use MainWorking, clear
keep if age>=25 & age<=55
collapse (mean) teacher_ownreg [aweight=perwt], by(black bornsouth year)

*Panel A
twoway connect teacher_ownreg year if black==1 & bornsouth==1, lpattern(solid) lcolor(black) lwidth(thin) mcolor(black) msymbol(circle) msize(small)  || ///
	   connect teacher_ownreg year if black==0 & bornsouth==1, lpattern(shortdash) lcolor(gs4)   lwidth(thin) mcolor(gs4)   msymbol(square) msize(small)  || /// 	   
	   connect teacher_ownreg year if black==1 & bornsouth==0, lpattern(dash_dot) lcolor(gs8)   lwidth(thin) mcolor(gs8)   msymbol(triangle) msize(small)  || ///
	   connect teacher_ownreg year if black==0 & bornsouth==0, lpattern(longdash) lcolor(gs12)  lwidth(thin) mcolor(gs12)  msymbol(diamond) msize(small)  ///
	   title(Panel A: Teacher Share by Race and Region, size(medsmall)) xtitle(Year, size(medsmall)) ytitle(Teacher Share, size(medsmall)) ///
	   xline(1960, lcolor(black) lpattern(dash)) ///
	   legend(label(1 "Southern Black")  label(2 "Southern White") label(3 "Northern Black") label(4 "Northern White") rows(2) size(medsmall)) ///
	   graphregion(ifcolor(white) fcolor(white) lcolor(white) icolor(white)) saving(A, replace)


*Panel B
reshape wide teacher_ownreg, i(year bornsouth) j(black)
reshape wide teacher_ownreg*, i(year ) j(bornsouth)

g BWDiff_South=teacher_ownreg11 - teacher_ownreg01
g BWDiff_North=teacher_ownreg10 - teacher_ownreg00

twoway connect BWDiff_South year, lpattern(solid) lcolor(black) lwidth(thin) mcolor(black) msymbol(circle) msize(small) || ///
	   connect BWDiff_North year, lpattern(dash) lcolor(gs8) lwidth(thin) mcolor(gs8) msymbol(square) msize(small) ///
	   title(Panel B: Teacher Share Difference by Region, size(medsmall)) xtitle(Year, size(medsmall)) ytitle(Black-White Difference in Teacher Share, size(medsmall)) ///
	   xline(1960, lcolor(black) lpattern(dash)) ///
	   legend(label(1 "South")  label(2 "North") rows(1) size(medsmall)) ///
	   graphregion(ifcolor(white) fcolor(white) lcolor(white) icolor(white)) saving(B, replace)

graph combine  A.gph B.gph,  rows(2) xsize(12) ysize(20) graphregion(ifcolor(white) fcolor(white) lcolor(white) icolor(white)) 

	   
	   
	   
	   
	   
*Figure 4: Main Census results   
use MainWorking, clear
keep if age>=25 & age<=55  
 
foreach x of varlist teacher_ownreg  teacher_newreg prof nonprof notworking {
di "`x'"
qui reg `x'   y1940 y1950 y1970 y1980 y1990 y2000  black bornsouth Sx1940 Bx1940 Sx1950 Bx1950 Sx1970 Bx1970 Sx1980 Bx1980 Sx1990 Bx1990 Sx2000 Bx2000 BxS BxSx1940 BxSx1950 BxSx1970 BxSx1980 BxSx1990 BxSx2000  i.statefip i.educ  male  age [aweight=perwt],  cluster(statefip)  
est sto `x'
matrix res`x' = [ _b[BxSx1940], _se[BxSx1940] \  _b[BxSx1950], _se[BxSx1950] \  0, 0 \  _b[BxSx1970], _se[BxSx1970] \  _b[BxSx1980], _se[BxSx1980] \  _b[BxSx1990], _se[BxSx1990] \  _b[BxSx2000], _se[BxSx2000]]
}


matrix years=[1940\1950\1960\1970\1980\1990\2000]	   
matrix res=[years, resteacher_ownreg, resteacher_newreg, resprof, resnonprof, resnotworking]   
svmat res
keep res*
keep in 1/7	   
rename res1 year	   
rename res2 teacher_ownreg
rename res3 se_teacher_ownreg	
rename res4 teacher_newreg
rename res5 se_teacher_newreg
rename res6 prof
rename res7 se_prof
rename res8 nonprof
rename res9 se_nonprof
rename res10 notworking
rename res11 se_notworking

local depvars="teacher_ownreg  teacher_newreg prof nonprof notworking"
foreach x of local depvars {
g min_`x'=`x'-1.96*se_`x'
g max_`x'=`x'+1.96*se_`x'
}

twoway connect teacher_ownreg year, lcolor(black) msize(small) mcolor(black) 	xline(1960, lcolor(black) lpattern(dash)) || ///
rcap min_teacher_ownreg max_teacher_ownreg year, lcolor(gs12) ///
title(Panel A: Teacher in Region of Birth, size(medium))  xtitle(Year, size(small)) ytitle(Black x South x Year, size(small)) ///
xtick(1940(10)2000) xlabel(1940(10)2000, labsize(small))   ylabel(-.15(.05).15, labsize(small)  gmin gmax)  ///
graphregion(ifcolor(white) fcolor(white) lcolor(white) icolor(white)) legend(off) saving(A, replace) aspect(.8) graphregion(margin(0 0 0 0))

twoway connect nonprof year, lcolor(black) msize(small) mcolor(black) 	xline(1960, lcolor(black) lpattern(dash)) || ///
rcap min_nonprof max_nonprof year, lcolor(gs12) ///
title(Panel B: Non-Professional Occupation, size(medium))  xtitle(Year, size(small)) ytitle(Black x South x Year, size(small)) ///
xtick(1940(10)2000) xlabel(1940(10)2000, labsize(small))   ylabel(-.15(.05).15, labsize(small)  gmin gmax) ///
graphregion(ifcolor(white) fcolor(white) lcolor(white) icolor(white)) legend(off) saving(B, replace)   aspect(.8) graphregion(margin(0 0 0 0))

twoway connect teacher_newreg year, lcolor(black) msize(small) mcolor(black) 	xline(1960, lcolor(black) lpattern(dash)) || ///
rcap min_teacher_newreg max_teacher_newreg year, lcolor(gs12) ///
title(Panel C: Teacher in  New Region, size(medium))  xtitle(Year, size(small)) ytitle(Black x South x Year, size(small)) ///
xtick(1940(10)2000) xlabel(1940(10)2000, labsize(small))  ylabel(-.15(.05).15, labsize(small)  gmin gmax) ///
graphregion(ifcolor(white) fcolor(white) lcolor(white) icolor(white)) legend(off) saving(C, replace) aspect(.8) graphregion(margin(0 0 0 0))

twoway connect prof year, lcolor(black) msize(small) mcolor(black) 	xline(1960, lcolor(black) lpattern(dash)) || ///
rcap min_prof max_prof year, lcolor(gs12) ///
title(Panel D: Other Professional Occupation, size(medium))  xtitle(Year, size(small)) ytitle(Black x South x Year, size(small)) ///
xtick(1940(10)2000) xlabel(1940(10)2000, labsize(small))  ylabel(-.15(.05).15, labsize(small)  gmin gmax) ///
graphregion(ifcolor(white) fcolor(white) lcolor(white) icolor(white)) legend(off) saving(D, replace)  aspect(.8) graphregion(margin(0 0 0 0))

twoway connect notworking year, lcolor(black) msize(small) mcolor(black) 	xline(1960, lcolor(black) lpattern(dash)) || ///
rcap min_notworking max_notworking year, lcolor(gs12) ///
title(Panel E: Not Working, size(medium))  xtitle(Year, size(small)) ytitle(Black x South x Year, size(small)) ///
xtick(1940(10)2000) xlabel(1940(10)2000, labsize(small))  ylabel(-.15(.05).15, labsize(small)  gmin gmax) ///
graphregion(ifcolor(white) fcolor(white) lcolor(white) icolor(white)) legend(off) saving(E, replace)  aspect(.8) graphregion(margin(0 0 0 0))




	   
*Appendix Table A6: Table version    
use MainWorking, clear
keep if age>=25 & age<=55  
   
foreach x of varlist teacher_ownreg  teacher_newreg prof nonprof notworking {
di "`x'"
qui reg `x' black 	bornsouth   y1940 y1950 y1970 y1980 y1990 y2000 	BxS 	Bx1940 Bx1950 Bx1970 Bx1980	Bx1990 Bx2000 	Sx1940 Sx1950 Sx1970 Sx1980 Sx1990 Sx2000   BxSx1940 BxSx1950 BxSx1970 BxSx1980 BxSx1990 BxSx2000  i.statefip i.educ  male  age [aweight=perwt],  cluster(statefip)  
est sto `x'
}

outreg2 [*] using T1, keep(black 	bornsouth   y1940 y1950 y1970 y1980 y1990 y2000 	BxS 	Bx1940 Bx1950 Bx1970 Bx1980	Bx1990 Bx2000 	Sx1940 Sx1950 Sx1970 Sx1980 Sx1990 Sx2000   BxSx1940 BxSx1950 BxSx1970 BxSx1980 BxSx1990 BxSx2000 )  dec(3)   nor2  replace    




*Appendix Figure A5: No age restriction and no controls
use MainWorking, clear
   
foreach x of varlist teacher_ownreg  teacher_newreg prof nonprof notworking {
di "`x'"
qui reg `x'   y1940 y1950 y1970 y1980 y1990 y2000  black bornsouth Sx1940 Bx1940 Sx1950 Bx1950 Sx1970 Bx1970 Sx1980 Bx1980 Sx1990 Bx1990 Sx2000 Bx2000 BxS BxSx1940 BxSx1950 BxSx1970 BxSx1980 BxSx1990 BxSx2000  [aweight=perwt],  cluster(statefip)  
est sto `x'
matrix res`x' = [ _b[BxSx1940], _se[BxSx1940] \  _b[BxSx1950], _se[BxSx1950] \  0, 0 \  _b[BxSx1970], _se[BxSx1970] \  _b[BxSx1980], _se[BxSx1980] \  _b[BxSx1990], _se[BxSx1990] \  _b[BxSx2000], _se[BxSx2000]]
}


matrix years=[1940\1950\1960\1970\1980\1990\2000]	   
matrix res=[years, resteacher_ownreg, resteacher_newreg, resprof, resnonprof, resnotworking]   
svmat res
keep res*
keep in 1/7	   
rename res1 year	   
rename res2 teacher_ownreg
rename res3 se_teacher_ownreg	
rename res4 teacher_newreg
rename res5 se_teacher_newreg
rename res6 prof
rename res7 se_prof
rename res8 nonprof
rename res9 se_nonprof
rename res10 notworking
rename res11 se_notworking

local depvars="teacher_ownreg  teacher_newreg prof nonprof notworking"
foreach x of local depvars {
g min_`x'=`x'-1.96*se_`x'
g max_`x'=`x'+1.96*se_`x'
}


twoway connect teacher_ownreg year, lcolor(black) msize(small) mcolor(black) 	xline(1960, lcolor(black) lpattern(dash)) || ///
rcap min_teacher_ownreg max_teacher_ownreg year, lcolor(gs12) ///
title(Panel A: Teacher in Region of Birth, size(medium))  xtitle(Year, size(small)) ytitle(Black x South x Year, size(small)) ///
xtick(1940(10)2000) xlabel(1940(10)2000, labsize(small))   ylabel(-.15(.05).15, labsize(small)  gmin gmax)  ///
graphregion(ifcolor(white) fcolor(white) lcolor(white) icolor(white)) legend(off) saving(A, replace) aspect(.8) graphregion(margin(0 0 0 0))

twoway connect nonprof year, lcolor(black) msize(small) mcolor(black) 	xline(1960, lcolor(black) lpattern(dash)) || ///
rcap min_nonprof max_nonprof year, lcolor(gs12) ///
title(Panel B: Non-Professional Occupation, size(medium))  xtitle(Year, size(small)) ytitle(Black x South x Year, size(small)) ///
xtick(1940(10)2000) xlabel(1940(10)2000, labsize(small))   ylabel(-.15(.05).15, labsize(small)  gmin gmax) ///
graphregion(ifcolor(white) fcolor(white) lcolor(white) icolor(white)) legend(off) saving(B, replace)   aspect(.8) graphregion(margin(0 0 0 0))

twoway connect teacher_newreg year, lcolor(black) msize(small) mcolor(black) 	xline(1960, lcolor(black) lpattern(dash)) || ///
rcap min_teacher_newreg max_teacher_newreg year, lcolor(gs12) ///
title(Panel C: Teacher in  New Region, size(medium))  xtitle(Year, size(small)) ytitle(Black x South x Year, size(small)) ///
xtick(1940(10)2000) xlabel(1940(10)2000, labsize(small))  ylabel(-.15(.05).15, labsize(small)  gmin gmax) ///
graphregion(ifcolor(white) fcolor(white) lcolor(white) icolor(white)) legend(off) saving(C, replace) aspect(.8) graphregion(margin(0 0 0 0))

twoway connect prof year, lcolor(black) msize(small) mcolor(black) 	xline(1960, lcolor(black) lpattern(dash)) || ///
rcap min_prof max_prof year, lcolor(gs12) ///
title(Panel D: Other Professional Occupation, size(medium))  xtitle(Year, size(small)) ytitle(Black x South x Year, size(small)) ///
xtick(1940(10)2000) xlabel(1940(10)2000, labsize(small))  ylabel(-.15(.05).15, labsize(small)  gmin gmax) ///
graphregion(ifcolor(white) fcolor(white) lcolor(white) icolor(white)) legend(off) saving(D, replace)  aspect(.8) graphregion(margin(0 0 0 0))

twoway connect notworking year, lcolor(black) msize(small) mcolor(black) 	xline(1960, lcolor(black) lpattern(dash)) || ///
rcap min_notworking max_notworking year, lcolor(gs12) ///
title(Panel E: Not Working, size(medium))  xtitle(Year, size(small)) ytitle(Black x South x Year, size(small)) ///
xtick(1940(10)2000) xlabel(1940(10)2000, labsize(small))  ylabel(-.15(.05).15, labsize(small)  gmin gmax) ///
graphregion(ifcolor(white) fcolor(white) lcolor(white) icolor(white)) legend(off) saving(E, replace)  aspect(.8) graphregion(margin(0 0 0 0))


  
  
  
  
*Appendix Table A7: Heterogeneity	   
use MainWorking, clear
keep if age>=25 & age<=55  

foreach x of varlist teacher_ownreg  nonprof teacher_newreg prof  notworking {
qui reg `x'   y1940 y1950 y1970 y1980 y1990 y2000  black bornsouth Sx1940 Bx1940 Sx1950 Bx1950 Sx1970 Bx1970 Sx1980 Bx1980 Sx1990 Bx1990 Sx2000 Bx2000 BxS BxSx1940 BxSx1950 BxSx1970 BxSx1980 BxSx1990 BxSx2000  i.statefip i.educ age [aweight=perwt] if male==1 & age<40,  cluster(statefip)  
est sto `x'youngmale
qui reg `x'   y1940 y1950 y1970 y1980 y1990 y2000  black bornsouth Sx1940 Bx1940 Sx1950 Bx1950 Sx1970 Bx1970 Sx1980 Bx1980 Sx1990 Bx1990 Sx2000 Bx2000 BxS BxSx1940 BxSx1950 BxSx1970 BxSx1980 BxSx1990 BxSx2000  i.statefip i.educ age [aweight=perwt] if male==1 & age>=40,  cluster(statefip)  
est sto `x'oldmale
qui reg `x'   y1940 y1950 y1970 y1980 y1990 y2000  black bornsouth Sx1940 Bx1940 Sx1950 Bx1950 Sx1970 Bx1970 Sx1980 Bx1980 Sx1990 Bx1990 Sx2000 Bx2000 BxS BxSx1940 BxSx1950 BxSx1970 BxSx1980 BxSx1990 BxSx2000  i.statefip i.educ age [aweight=perwt] if male==0 & age<40,  cluster(statefip)  
est sto `x'youngfemale
qui reg `x'   y1940 y1950 y1970 y1980 y1990 y2000  black bornsouth Sx1940 Bx1940 Sx1950 Bx1950 Sx1970 Bx1970 Sx1980 Bx1980 Sx1990 Bx1990 Sx2000 Bx2000 BxS BxSx1940 BxSx1950 BxSx1970 BxSx1980 BxSx1990 BxSx2000  i.statefip i.educ age [aweight=perwt] if male==0 & age>=40,  cluster(statefip)  
est sto `x'oldfemale
}

outreg2 [*] using T1, keep(BxSx1940 BxSx1950 BxSx1970 BxSx1980 BxSx1990 BxSx2000 )  dec(3)  nocons nor2  replace 

	   	   


*Table 4: Earnings Effects
use MainWorking, clear 
keep if black==1 & livesouth==1 
qui reg learn teacher  i.statefip i.educ  male  age if year==1950  [aweight=perwt], robust
est sto earnd1950
qui reg learn teacher  i.statefip i.educ  male  age if year==1960  [aweight=perwt], robust
est sto earnd1960
qui reg learn teacher  i.statefip i.educ  male  age if year==1970  [aweight=perwt], robust 
est sto earnd1970
qui reg learn teacher  i.statefip i.educ  male  age if year==1980  [aweight=perwt], robust
est sto earnd1980

outreg2 [*] using T1, keep(teacher)  dec(2)  nocons nor2  replace 

*means quoted in text
sum learn if teacher==1 & year==1960
sum learn if teacher==1 & year==1980
sum learn if teacher==0 & year==1960
sum learn if teacher==0 & year==1980


*Table A8: Zero earners
use MainWorking, clear 
keep if black==1 & livesouth==1 
g learn_transf=ln(incwage+1)

qui reg learn_transf teacher  i.statefip i.educ  male  age if year==1950  [aweight=perwt], robust
est sto earnd1950
qui reg learn_transf teacher  i.statefip i.educ  male  age if year==1960  [aweight=perwt], robust
est sto earnd1960
qui reg learn_transf teacher  i.statefip i.educ  male  age if year==1970  [aweight=perwt], robust 
est sto earnd1970
qui reg learn_transf teacher  i.statefip i.educ  male  age if year==1980  [aweight=perwt], robust
est sto earnd1980

outreg2 [*] using T1, keep(teacher)  dec(2)  nocons nor2  replace 


*Table A9: No Controls
*no controls
use MainWorking, clear 
keep if black==1 & livesouth==1 
qui reg learn teacher  if year==1950  [aweight=perwt], robust
est sto earnd1950
qui reg learn teacher  if year==1960  [aweight=perwt], robust
est sto earnd1960
qui reg learn teacher  if year==1970  [aweight=perwt], robust 
est sto earnd1970
qui reg learn teacher  if year==1980  [aweight=perwt], robust
est sto earnd1980

outreg2 [*] using T1, keep(teacher)  dec(2)  nocons nor2  replace 









